<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        div{width: 20px;height: 20px;background: #000;color: #fff;line-height: 20px;text-align: center;position: absolute;left:0;top:0;}
    </style>
</head>
<body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    <div>7</div>
</body>
<script>
    var adiv = document.querySelectorAll("div");

    document.onmousemove = function(eve){
        var e = eve ? eve : window.event;
        // e.pageX
        // e.pageY
        // 先操作最后一个元素，依次找前一个元素的位置
        for(var i=adiv.length-1;i>0;i--){
            adiv[i].style.left = adiv[i-1].offsetLeft + "px";
            adiv[i].style.top = adiv[i-1].offsetTop + "px";
        }
        // 最后让第一个元素，找鼠标的位置
        adiv[0].style.left = e.pageX + "px";
        adiv[0].style.top = e.pageY + "px";
    }
</script>
</html>